Skip to main content

Executor Modules

Overview

Executor modules (IExecutor) handle the execution of transactions within ERC-7579 smart accounts. They manage transaction batching, specialized execution patterns, and execution validation.

Interface Definition

interface IExecutor is IModule {
error AlreadyInitialized(address smartAccount);
error NotInitialized(address smartAccount);
}

Implementation Example: Basic Executor

Based on the provided MockExecutor implementation:

contract BasicExecutor is IExecutor {
// Tracks initialized accounts
mapping(address => bool) public initializedAccounts;
uint256 public counter; // Example state variable

// Core Module Functions
function onInstall(bytes calldata) external {
if (initializedAccounts[msg.sender]) {
revert AlreadyInitialized(msg.sender);
}
initializedAccounts[msg.sender] = true;
}

function onUninstall(bytes calldata) external {
if (!initializedAccounts[msg.sender]) {
revert NotInitialized(msg.sender);
}
initializedAccounts[msg.sender] = false;
}

function isModuleType(uint256 moduleTypeId) external pure returns (bool) {
return moduleTypeId == MODULE_TYPE_EXECUTOR;
}

function isInitialized(address smartAccount) external view returns (bool) {
return initializedAccounts[smartAccount];
}

// Example execution function
function incrementCounter() external {
if (!initializedAccounts[msg.sender]) {
revert NotInitialized(msg.sender);
}
counter++;
}
}

Extended Implementation: Advanced Executor

contract AdvancedExecutor is IExecutor {
mapping(address => bool) public initializedAccounts;

event TransactionExecuted(
address indexed target,
uint256 value,
bytes data,
bool success
);

function executeTransaction(
address target,
uint256 value,
bytes calldata data
) external payable returns (bool success, bytes memory result) {
if (!initializedAccounts[msg.sender]) {
revert NotInitialized(msg.sender);
}

(success, result) = target.call{value: value}(data);
emit TransactionExecuted(target, value, data, success);
}

function executeBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata data
) external payable returns (bool[] memory successes) {
// batch tx execution logic here
}
}

Common Use Cases

  1. Transaction Management

    • Single transaction execution
    • Batch transaction processing
    • Atomic transaction execution
  2. Specialized Operations

    • DeFi interactions
    • Multi-contract calls
    • Gas-optimized executions
  3. Access Control

    • Role-based execution
    • Value limits
    • Operation restrictions

Security Considerations

  1. Transaction Safety

    • Validate call targets
    • Check value transfers
    • Handle failed executions
  2. State Management

    • Atomic operations
    • Reentrance protection
    • State consistency
  3. Access Control

    • Initialization checks
    • Permission validation
    • Value limits

Best Practices

  1. Implementation Guidelines

    • Use events for tracking
    • Implement proper checks
    • Handle failures gracefully
  2. Gas Optimization

    • Batch similar operations
    • Minimize storage usage
    • Use efficient patterns
  3. Error Handling

    • Custom error messages
    • Proper revert conditions
    • Success validation